﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ArgusLib.Threading.Collections
{
	public class SynchronizedListWrapper<T> : SynchronizedListBase<T>
	{
		IList<T> list;

		public SynchronizedListWrapper(IList<T> list)
			: this(list, new object()) { }

		public SynchronizedListWrapper(IList<T> list, object syncRoot)
			: base(syncRoot)
		{
			this.list = list;
		}

		protected override ISynchronizedEnumerator<T> GetEnumeratorCore()
		{
			return new SynchronizedEnumeratorWrapper<T>(this.list.GetEnumerator(), this.SyncRoot);
		}

		protected override int CountGetCore() { return this.list.Count; }
		protected override bool IsReadOnlyGetCore() { return this.list.IsReadOnly; }
		protected override void AddCore(T item) { this.list.Add(item); }
		protected override void ClearCore() { this.list.Clear(); }
		protected override bool ContainsCore(T item) { return this.list.Contains(item); }
		protected override void CopyToCore(T[] array, int index) { this.list.CopyTo(array, index); }
		protected override bool RemoveCore(T item) { return this.list.Remove(item); }
		protected override int IndexOfCore(T item) { return this.list.IndexOf(item); }
		protected override void InsertCore(int index, T item) { this.list.Insert(index, item); }
		protected override T ItemGetCore(int index) { return this.list[index]; }
		protected override void ItemSetCore(int index, T item) { this.list[index] = item; }
		protected override void RemoveAtCore(int index) { this.list.RemoveAt(index); }

		public int Count { get { return ((ICollection<T>)this).Count; } }
		public bool IsReadOnly { get { return ((ICollection<T>)this).IsReadOnly; } }
		public T this[int index]
		{
			get { return ((IList<T>)this)[index]; }
			set { ((IList<T>)this)[index] = value; }
		}

		public void Add(T item) { ((ICollection<T>)this).Add(item); }
		public void Clear() { ((ICollection<T>)this).Clear(); }
		public bool Contains(T item) { return ((ICollection<T>)this).Contains(item); }
		public void CopyTo(T[] array, int index) { ((ICollection<T>)this).CopyTo(array, index); }
		public bool Remove(T item) { return ((ICollection<T>)this).Remove(item); }
		public int IndexOf(T item) { return ((IList<T>)this).IndexOf(item); }
		public void Insert(int index, T item) { ((IList<T>)this).Insert(index, item); }
		public void RemoveAt(int index) { ((IList<T>)this).RemoveAt(index); }
	}
}
